package com.nidu.demo.user.executor.query;

import com.alibaba.cola.dto.MultiResponse;
import com.nidu.demo.user.convertor.UserCriteriaConvertor;
import com.nidu.demo.user.dto.UserListQry;
import com.nidu.demo.user.convertor.UserConvertor;
import com.nidu.demo.user.dto.UserCO;
import com.nidu.demo.user.gateway.UserGateway;
import com.nidu.demo.user.model.User;
import com.nidu.demo.user.model.UserCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@RequiredArgsConstructor
public class UserListQryExe {

    private final UserGateway gateway;

    private final UserConvertor convertor;

    private final UserCriteriaConvertor criteriaConvertor;

    public MultiResponse<UserCO> execute(UserListQry qry) {
        UserCriteria criteria = criteriaConvertor.toDataObject(qry);
        List<User> users = gateway.listByCondition(criteria);
        List<UserCO> usersCOS = convertor.toClientObjects(users);
        return MultiResponse.of(usersCOS);
    }
}
